Learning Objectives

After completing this lesson, you’ll be able to:

Instructions

In this lesson, you will:

Resources

Exercise

Sven

Sven has built the DensityEvaluator custom transformer that calculates density for a given area. His workspace reads Vancouver neighborhoods data and writes population density values for 2001 and 2011. Because he set the Attribute References parameter to Handle With User Parameters, the transformer already handles the schema correctly. Sven wants to make it more generic, so other teams can choose their own output attribute name and units.

In this exercise, you will:

1) Open Starting Workspace

2) Edit the Custom Transformer to Use a User-Defined Output Attribute Name

The workspace currently holds two instances of the custom transformer, and both produce an attribute with the same name, DensityResult. It would be more useful if the user of the custom transformer could define that name themselves.

Setting Result to a User Parameter

Setting the name of the new attribute

Configuring both custom transformers

3) Set Parameter Labels

The label for the attribute to analyze is currently TotalPopulation2001, which is specific to this one scenario. Adding a Population attribute to the transformer's input prompts the transformer user to choose an attribute that supplies the population values. That creates a new POPULATION user parameter, which the ExpressionEvaluator then needs to use.

Adding a Population attribute

4) Implement Units Selection

The workspace currently calculates the number of items, in this exercise persons, per square kilometer of land. That suits the original scenario, but other uses of this transformer might need different units. A Choice parameter lets the user pick the units they want.

Configuring the DensityUnits parameter

5) Apply the Units Parameter

You have defined a user parameter for the units, but the custom transformer does not use it yet. The AreaCalculator's Multiplier field is where the chosen units take effect.

Choosing DensityUnits

Choosing the value for DensityUnits

 

Tips

 

Challenge

Your DensityEvaluator now lets the user name the output attribute and choose the density units. One thing it cannot do is weight the calculation, so every neighborhood counts equally no matter how reliable its figures are. Your source data has no field you could reasonably weight by, so you will need to generate a test attribute before you can prove the weighting works.

In this challenge, you will:

 

Challenge Answer: Open after attempting the challenge.

The weighting comes from an incoming attribute, which means the custom transformer has to handle it in its schema. You generate a test attribute in the workspace, expose it inside the transformer, then branch on whether the user supplied it.

1) Add RandomNumberGenerator

Your source data has no field you could reasonably use to weight the output, so you generate one.

Adding a RandomNumberGenerator

2) Expose the Attribute in the Custom Transformer

The new attribute exists in the workspace but not inside the custom transformer. Exposing it on the Input port makes it available to the transformer's logic, and also creates a user parameter for it.

Exposing WeightedAttribute

Configuring the WeightedAttribute user parameter.

3) Duplicate the ExpressionEvaluator

Records that carry a weighting value need a different equation from those that do not, so the transformer needs two ExpressionEvaluators and a Tester to choose between them.

Duplicated ExpressionEvaluators in parallel

4) Set Up the Tester

The test decides which records get weighted. Records with a weighting value greater than zero take the Passed port.

Tester configuration

Choosing the attribute not user parameter

5) Adjust the Equation

Now that the attribute is exposed in the custom transformer, you can use it in the equation that calculates density. The ExpressionEvaluator connected to the Tester's Passed port is the one that handles the weighted records.

Results without weighting

It may seem odd, especially to experienced users, that you use the attribute in the expression instead of the user parameter. This is part of how FME handles the behavior automatically. It prevents the author from needing to know about user parameters and how to use them, and it uses hidden functionality to replace the attribute with the user parameter wherever necessary.

🔍 Check your results

Open the completed workspace: Completed Advanced Workspace (C:\FMEData\Workspaces\AdvancedDataTransformation\parameterize-a-custom-transformer-complete-advanced.fmw).